
package com.dps.omc.service.impl;
import com.dps.omc.model.BizType;
import com.dps.omc.model.BizUnit;
import com.dps.omc.model.User;
import com.dps.common.utils.IdGenerator;
import com.dps.omc.dao.IUserBizRightsDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dps.common.service.impl.AbstractPageService;
import com.dps.omc.model.UserBizRights;
import com.dps.omc.service.IUserBizRightsService;

import java.util.List;

@SuppressWarnings("unchecked")
@Service("UserBizRightsServiceImpl")

public class UserBizRightsServiceImpl extends AbstractPageService<IUserBizRightsDAO,UserBizRights> implements IUserBizRightsService {

	@Autowired
	private IUserBizRightsDAO userBizRightsDAO;
	@Override
	public boolean getEnableDataPerm() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public IUserBizRightsDAO getDao() {
		return userBizRightsDAO;
	}

	@Override
	public UserBizRights create(User user, BizUnit bizUnit, BizType bizType, Boolean mailAble, Boolean dbaFlag, User creater) {

		UserBizRights userBizRights = new UserBizRights();
		userBizRights.setId(IdGenerator.createNewId());
		userBizRights.setUserId(user.getId());
		userBizRights.setUserName(user.getUserName());
		userBizRights.setRealName(user.getRealName());
		userBizRights.setBizUnitId(bizUnit.getId());
		userBizRights.setBizUnit(bizUnit.getUnitName());
		userBizRights.setBizUnitName(bizUnit.getNote());
		userBizRights.setBizTypeId(bizType.getId());
		userBizRights.setBizType(bizType.getTypeName());
		userBizRights.setBizTypeName(bizType.getNote());
		userBizRights.setMailAble(mailAble);
		userBizRights.setDbaFlag(dbaFlag);
		userBizRights.setCreaterId(creater.getId());
		userBizRights.setCreaterName(creater.getRealName());
		userBizRights.setEmail(user.getEmail());
		this.add(userBizRights);
		return userBizRights;
	}

	@Override
	public void create(User user, List<BizUnit> bizUnits, List<BizType> bizTypes, Boolean mailAble, Boolean dbaFlag, User creater) {
		this.deleteByProperty("userId",user.getId());
		for(BizUnit bizUnit:bizUnits)
		{
			for(BizType bizType:bizTypes)
			{
				create(user,bizUnit,bizType,mailAble,dbaFlag,creater);
			}
		}
	}

	@Override
	public List<UserBizRights> findUsersByUnitsAndTypes(List<String> bizUnits, List<String> bizTypes) {
		return getDao().findUsersByUnitsAndTypes(bizUnits,bizTypes);
	}
}
